package 力扣日常刷题.木22二月.第13天219;

/**
 * @author 帅小伙
 * @date 2022/2/19
 * @description
 */
public class Demo101乘积最大子数组 {


    public int maxProduct(int[] nums) {
        int maxF = nums[0], minF = nums[0], ans = nums[0];
        int length = nums.length;

        for (int i = 1; i < length; i++) {
            int mx = maxF, mn = minF;
            maxF = Math.max(mx * nums[i], Math.max(nums[i], nums[i] * mn));
            minF = Math.min(mn * nums[i], Math.min(nums[i], nums[i] * mx));
            ans = Math.max(maxF,ans);
        }
        return ans;
    }

}
